<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>豆瓣图书</title>
    <script src="lib/ajax.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <style>
        *{margin: 0;padding: 0;}
        #container{
            margin-left: 150px;
        }

        .item{
            display: flex;
            margin: 20px;
        }

        .pic{
            width: 50px;
            height: 70px;
            margin-right: 20px;
        }

        .pic>img{
            width: 100%;
            height: 100%;
        }

        .text{
            width: 300px;
            display: flex;
            flex-direction: column;
            justify-content: space-around;
        }

        .title{
            color: deepskyblue;
            font-size: 16px;
        }

        .commentart{
            display: flex;
            font-size: 12px;
        }

        .star{
            color: brown;
            margin-right: 5px;
        }

        .number{
            color: #333;
        }

        .actor{
            color: #666;
            font-size: 12px;
        }
    </style>
    
</head>
<body>
    <div id="container">
        <!-- <div class="item">
            <div class="pic">
                <img src="" alt="">
            </div>
            <div class="text">
                <p class="title">1</p>
                <div class="commentart">
                    <p class="star">1</p>
                    <p class="number">1</p>
                </div>
                <p class="actor">1</p>
            </div>
        </div> -->
    </div>
    <script>
        var url = "http://47.108.197.28:8000/book";
        var xhr = new XMLHttpRequest();
        xhr.open("GET",url,true);
        xhr.send();
        xhr.onreadystatechange = function(){
            if(xhr.readyState ===4){
                if(xhr.status >=200 && xhr.status <300){
                    var res = JSON.parse(xhr.responseText);
                    res.forEach(item=>{
                        var {coverImage,title,rating,evaluate,labels,price} = item;
                        labels.push(price);
                        labels = labels.join("/") + "元";
                        console.log(labels);
                        
                        var temple = `
                            <div class="item">
                                <div class="pic">
                                    <img src="https://images.weserv.nl/?url=${coverImage}" alt="">
                                </div>
                                <div class="text">
                                    <p class="title">${title}</p>
                                    <div class="commentart">
                                        <p class="star">${rating}</p>
                                        <p class="number">(${evaluate}人评价)</p>
                                    </div>
                                    <p class="actor">${labels}</p>
                                </div>
                            </div>
                        `;
                        $("#container").append(temple);
                    })
                    
                }
            }
        }
    </script>
</body>
</html>